package daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;





import entity.Usedhouse;

public class UsedHouserDaoImpl extends HibernateDaoSupport implements dao.IUsedHouseDao {
	
	/* (non-Javadoc)
	 * @see usedHouse.dao.impl.IUsedHouserDao#findAllInput(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	
	public List<Usedhouse> findAllInput(Usedhouse uh){
		StringBuffer hql=new StringBuffer(" from Usedhouse as model where 1=1");
		if(uh.getInfotypes().getId()!=null&&!"".equals(uh.getInfotypes().getId())){
			hql.append(" and model.infotypes.id="+uh.getInfotypes().getId());
		}
		if(uh.getArea().getId()!=null&&!"".equals(uh.getArea().getId())){
			hql.append(" and model.area.id="+uh.getArea().getId());
		}
		if(uh.getHousetypes().getId()!=null&&!"".equals(uh.getHousetypes().getId())){
			hql.append(" and model.Housetypes.id="+uh.getHousetypes().getId());
		}
	
		if(uh.getUhArea()!=null&&!"".equals(uh.getUhArea())){
			hql.append(" and model.uhArea "+uh.getUhArea());
		}
		if(uh.getUhPrice()!=null&&!"".equals(uh.getUhPrice())){
			hql.append(" and model.uhPrice "+uh.getUhPrice());
		}
		if(uh.getUhFitment()!=null&&!"".equals(uh.getUhFitment())){
			hql.append(" and model.uhFitment="+uh.getUhFitment());
		}
		if(uh.getUhIssueTime()!=null&&!"".equals(uh.getUhIssueTime())){
			hql.append(" and  datediff( now(),u.model.uhIssueTime) BETWEEN 0 and "+uh.getUhIssueTime());
		}
		if(uh.getUhPathname()!=null&&!"".equals(uh.getUhPathname())){
			hql.append(" and model.uhPathname like '%"+uh.getUhPathname()+"%'");
		}

		return getHibernateTemplate().find(hql.toString());
	}
	
	
	public List<Usedhouse> findUsedhouseAllinfotypesIdAnd(int infotypeId){
		String hql=" from Usedhouse as model where model.infotypes.id="+infotypeId;
		List<Usedhouse> listUsedhouse=getHibernateTemplate().find(hql);
		if(listUsedhouse.size()>8){
			return listUsedhouse.subList(0, 9);
		}
		return listUsedhouse;
	}
	
	public Usedhouse findUsedhouseAllUsedHouseId(int UsedHouseId){
		String hql=" from Usedhouse as model where model.id="+UsedHouseId;
		return (Usedhouse)getHibernateTemplate().find(hql).get(0);
	}
}
